package com.dingwei.lesyndrome.mvp.presenter;

import com.dingwei.lesyndrome.base.FailsBean;
import com.dingwei.lesyndrome.base.MyBaseBean;
import com.dingwei.lesyndrome.bean.MyNewsBean;
import com.dingwei.lesyndrome.custom.myCallback;
import com.dingwei.lesyndrome.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class MyNewsPresenter extends basePresenter {

    private Contract.MyNewsView myNewsView;

    public MyNewsPresenter(Contract.MyNewsView view) {
        super(view);
        this.myNewsView = view;
    }

    public void initData(int page, final boolean isRefresh, boolean isShowDialog) {
        RequestParams rp = new RequestParams(URLS.HOST + URLS.MSG_LIST);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        rp.addBodyParameter("cpage", page + "");
        x.http().post(rp, new myCallback(BaseActivity.context, MyNewsBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                MyNewsBean bean = (MyNewsBean) baseBean;
                if (isRefresh){
                    myNewsView.onRefresh(bean);
                }else {
                    myNewsView.onLoadMore(bean);
                }
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                myNewsView.onFail();
            }
        });
    }
}
